<?php

namespace App\Http\Controllers\Admin;

use App\Models\GoodsClass;
use App\Services\CommonService;
use App\Models\Category;
use App\Models\Goods;
use App\Services\GoodsService;
use Illuminate\Http\Request;

class ModulesController extends BaseController
{
    /**
     * 获取商品列表
     */
    public function getGoodsList(Request $request){
        $cate_id = $request->input('cate_id');
        $goods_name = $request->input('goods_name','');
        $page = $request->input('page',1);
        $pageSize = $request->input('pageSize',12);
        $where[]= ['g.status',GoodsService::GOODS_STATUS_PUT];
        if(!empty($request['cate_id'])){
            $pid=GoodsClass::query()->where('id',$request['cate_id'])->value('pid');
            if($pid>0){
                $where[] = ['g.subclass_id',$request['cate_id']];
            }else{
                $where[] = ['g.category_id',$request['cate_id']];
            }
        }
        $goods_list = Goods::GetGoodsListAndCategory($where,$goods_name, $page, $pageSize);
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'获取成功',$goods_list);
    }



    /**
     * 获取筛选全部二级分类
     */
    public function getCategory(){
        $cate_list = Category::GetSonAllCate();
        return ReturnMsg(CommonService::HTTP_CODE_SUCCESS,'获取成功',$cate_list);
    }


}
